import contextvars

from loguru import logger


trace_context = contextvars.ContextVar("trace", default="-")


def singleton(cls):
    """单例装饰器"""
    instances = {}

    def get_instance(*args, **kwargs):
        if cls not in instances:
            instances[cls] = cls(*args, **kwargs)
        return instances[cls]

    return get_instance


def split_list(input_list, chunk_size):
    if len(input_list) <= chunk_size:
        return [input_list]
    logger.info("list size>100, input_list=" + str(input_list))
    return [input_list[i:i + chunk_size] for i in range(0, len(input_list), chunk_size)]